<?php

namespace App\Http\Controllers\Api;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Model\TogetherGame;

class TogetherGameController extends BaseController
{
    protected $togetherGameModel;//一起玩model

    public function __construct(Request $request)
    {
        parent::__construct($request);
        $this->togetherGameModel = new TogetherGame();
    }

    //获取一起玩游戏列表
    public function gameList(Request $request){
        $page = $request->get('page',1);//当前页
        $limit = $request->get('limit',10);//每页条数
        $searchId = $request->get('search_id',0);//搜索id
        $kwd = $request->get('kwd','');//搜索名称
        $status = $request->get('status',0);//搜索状态
        //数据获取
        $data = $this->togetherGameModel->getGameLsit($page, $limit, $searchId, $kwd, $status);
        return $this->toJson(self::SUCCESS, $data);
    }

    //数据添加修改
    public function gameAddUpdate(Request $request){
        $id = $request->post('id',0);//数据id
        $gameName = $request->post('game_name','');//游戏名称
        $diamond_value = $request->post('diamond_value',0);//钻石限制
        $jump_url = $request->post('jump_url','');//跳转地址
        $video_url = $request->post('video_url','');//视频链接
        $default_url = $request->post('default_url','');//默认图
        $icon_url = $request->post('icon_url','');//icon图链接
        $scale = $request->post('scale','');//视频比例值
        $sort = $request->post('sort',0);//排序
        $status = $request->post('status',2);//显示状态1=开启 2=关闭
        if(empty($gameName)){
            return $this->toJson(self::PARAM_ERROR,[],'游戏名称不能为空');
        }
        if(empty($diamond_value)){
            return $this->toJson(self::PARAM_ERROR,[],'钻石限制必填');
        }
        if(empty($jump_url)){
            return $this->toJson(self::PARAM_ERROR,[],'跳转地址限制必填');
        }
        if(empty($video_url)){
            return $this->toJson(self::PARAM_ERROR,[],'视频地址限制必填');
        }

        $changeStatus = $this->togetherGameModel->dataChange($id, $gameName, $diamond_value, $jump_url, $video_url, $scale, $sort, $status, $default_url, $icon_url);
        return $this->toJson(self::SUCCESS, $changeStatus);
    }

    //删除数据
    public function deleteGame(Request $request){
        $id = $request->post('id',0);
        if(empty($id)){
            return $this->toJson(self::PARAM_ERROR);
        }
        $changeStatus = $this->togetherGameModel->deleteGame($id);
        return $this->toJson(self::SUCCESS, $changeStatus);
    }

    //一起玩游戏开关控制
    public function gameOpen(){
        $data = $this->togetherGameModel->gameOpenList();
        return $this->toJson(self::SUCCESS, $data);
    }

    //一起玩游戏总功能配置
    public function setGameOpen(Request $request){
        $status = $request->post('status',2);//开关状态 1开启 2=关闭
        $diamond = $request->post('diamond',0);//钻石
        $data = $this->togetherGameModel->setGameOpen($status, $diamond);
        return $this->toJson(self::SUCCESS, $data);
    }

    //一起玩-签到列表
    public function daySign(Request $request){
        $page = $request->get('page',1);//当前页
        $limit = $request->get('limit',10);//每页条数
        $data = $this->togetherGameModel->daySign($page, $limit);
        return $this->toJson(self::SUCCESS, $data);
    }

    //一起玩-签到新增/修改
    public function setDaySign(Request $request){
        $id = $request->post('id',0);
        $signday = $request->post('sigin_type',1);//签到天
        $img = $request->post('img_url','');//签到图片
        $sendType = $request->post('send_type',1);//奖励类型1=娱乐积分 2=金豆 3=头像框/座驾/进场特效
        $sendId = $request->post('send_id',0);//奖励id type=3必传
        $sendNum = $request->post('send_num',1);//奖励数量
        $status = $request->post('status',2);//显示状态1=显示 2=不显示
        if(empty($sendType)){
            return $this->toJson(self::PARAM_ERROR, [],'奖励类型必填');
        }
        if(empty($img)){
            return $this->toJson(self::PARAM_ERROR, [],'签到图片必填');
        }
        if(empty($signday)){
            return $this->toJson(self::PARAM_ERROR, [],'签到天数必填');
        }
        if($sendType == 3 && empty($sendId)){
            return $this->toJson(self::PARAM_ERROR, [],'奖励id必填');
        }
        $data = $this->togetherGameModel->setDaySign($id, $signday, $img, $sendType, $sendId, $sendNum, $status);
        return $this->toJson(self::SUCCESS, $data);
    }
}